import SocketInstance from "../Tools/SocketInstance";
import { RequestCode, UserAction, playerData } from "../GlobalData/DataStruct";
import gameScene1 from "../Game/gameScene1"
import gameScene2 from "../Game/gameScene2"
import gameScene3 from "../Game/gameScene3"
import gameScene4 from "../Game/gameScene4"
import gameScene5 from "../Game/gameScene5"
import DataCenter from "../GlobalData/DataCenter";

export default class rankScene extends Laya.Script {

    constructor() { super(); }
    private return1_btn: Laya.Button       //返回按钮
    private rank_panel: Laya.Sprite        //排行榜
    private alltime: number

    private Nun_1: Laya.Text             //排行榜名字
    private Nun_2: Laya.Text
    private Nun_3: Laya.Text
    private Nun_4: Laya.Text
    private Nun_5: Laya.Text

    private time_1: Laya.Text             //排行榜时间
    private time_2: Laya.Text
    private time_3: Laya.Text
    private time_4: Laya.Text
    private time_5: Laya.Text

    onAwake() {
        /**发起排行榜请求 */
        SocketInstance.instance.sendRequest(RequestCode.USER, UserAction.GET_INFO, null)
        // DataCenter.allTime = gameScene1._intance.time1
    }

    onEnable(): void {
        //初始化变量
        this.initParams()
        //入场动画
        this.enterAni()
        //初始化绑定事件
        this.initEvent()
    }

    /**初始化绑定点击事件 */
    initEvent() {
        //给返回按钮绑定点击事件
        this.return1_btn.on(Laya.Event.CLICK, this, this.onReturn)

        //排行榜回调
        Laya.stage.on('get_info', this, this.rank_callback)
    }
    rank_callback(data: any) {
        // console.log(data)
        this.Nun_1.text = data.info[0].name
        this.Nun_2.text = data.info[1].name
        this.Nun_3.text = data.info[2].name
        this.Nun_4.text = data.info[3].name
        this.Nun_5.text = data.info[4].name

        this.time_1.text = data.info[0].time
        this.time_2.text = data.info[1].time
        this.time_3.text = data.info[2].time
        this.time_4.text = data.info[3].time
        this.time_5.text = data.info[4].time
    }

    onReturn() {
        Laya.Scene.open("mainScene.scene")
    }

    /**入场动画 */
    enterAni() {
        Laya.Tween.from(
            this.return1_btn,
            { y: -174 },
            700,
            Laya.Ease.strongInOut
        )

        Laya.Tween.from(
            this.rank_panel,
            { x: -500 },
            700,
            Laya.Ease.strongInOut
        )

    }

    /**初始化变量 */
    initParams() {
        //获取return按钮节点
        this.return1_btn = this.owner.getChildByName('return1_btn') as Laya.Button
        //获取排行榜节点
        this.rank_panel = this.owner.getChildByName('rank_panel') as Laya.Sprite
        //获取排名1的名字节点
        this.Nun_1 = this.rank_panel.getChildByName('p1') as Laya.Text

        //获取排名1
        this.Nun_1 = this.rank_panel.getChildByName('p1') as Laya.Text
        //获取排名2
        this.Nun_2 = this.rank_panel.getChildByName('p2') as Laya.Text
        //获取排名3
        this.Nun_3 = this.rank_panel.getChildByName('p3') as Laya.Text
        //获取排名4
        this.Nun_4 = this.rank_panel.getChildByName('p4') as Laya.Text
        //获取排名
        this.Nun_5 = this.rank_panel.getChildByName('p5') as Laya.Text
        //获取排名1的用时节点
        this.time_1 = this.rank_panel.getChildByName('t1') as Laya.Text
        //获取排名2的用时节点
        this.time_2 = this.rank_panel.getChildByName('t2') as Laya.Text
        //获取排名3的用时节点
        this.time_3 = this.rank_panel.getChildByName('t3') as Laya.Text
        //获取排名的用时节点
        this.time_4 = this.rank_panel.getChildByName('t4') as Laya.Text
        //获取排名5的用时节点
        this.time_5 = this.rank_panel.getChildByName('t5') as Laya.Text
    }

    onDisable(): void {
    }
}